package com.gxa.day2022_07_29_21.homework.others.log;

import com.gxa.day2022_07_29_21.homework.others.User;

import java.io.IOException;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

/**
 * @Description:
 * @Author: zhuiyi
 * @CreatTime: 2022/7/31 9:19
 **/
public class TestLog {
    public static void main(String[] args) throws IOException {
        //控制台输入登录 并校验
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入用户名：");
        String username = scanner.next();
        System.out.print("请输入密码：");
        String password = scanner.next();

        Login login = new Login();
        User user = login.login(username, password);
        //记录日志
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
        LogObj logObj = new LogObj();
        if(user != null){
            System.out.println("登录成功");
            String name = user.getName()+ "在";
            LocalTime now = LocalTime.now();
            String format = dateTimeFormatter.format(now);
            logObj.writeLog(name+ "\t" + format +"\t" +"登录系统");
        }else {
            System.out.println("登录失败");
            LocalTime now = LocalTime.now();
            String format = dateTimeFormatter.format(now);
            logObj.writeLog("非法用户" + username+"在" +"\t" +format.toString()
                    + "\t" +"企图登陆系统");
        }
    }
}
